package com.nanhai.buddhist.college.module.collegebase.api.department;

import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.module.collegebase.api.department.dto.DepartmentDTO;
import com.nanhai.buddhist.college.module.collegebase.convert.departments.DepartmentsConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.departments.DepartmentsDO;
import com.nanhai.buddhist.college.module.collegebase.service.departments.DepartmentsService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

import static com.nanhai.buddhist.college.module.collegebase.enums.ApiConstants.VERSION;

/**
 * @author AKai
 * @date 2022/8/23
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class DepartmentApiImpl implements DepartmentApi {

    @Resource
    private DepartmentsService departmentsService;

    @Override
    public CommonResult<DepartmentDTO> getDepartmentDTOById(String departmentsId) {
        DepartmentsDO departments = departmentsService.getDepartments(departmentsId);
        return CommonResult.success(DepartmentsConvert.INSTANCE.convertDepartmentDTO(departments));
    }

    @Override
    public CommonResult<List<DepartmentDTO>> getDepartmentDTOByIds(Collection<String> ids) {
        List<DepartmentsDO> departmentsList = departmentsService.getDepartmentsList(ids);
        return CommonResult.success(DepartmentsConvert.INSTANCE.convertDepartmentDTOList(departmentsList));
    }

    @Override
    public CommonResult<DepartmentDTO> getDepartmentDTOByClassesId(String classesId) {
        DepartmentsDO departmentsDO = departmentsService.getDepartmentDTOByClassesId(classesId);
        return CommonResult.success(DepartmentsConvert.INSTANCE.convertDepartmentDTO(departmentsDO));
    }

    @Override
    public CommonResult<List<DepartmentDTO>> getDepartmentDTOByClassesIds(Collection<String> ids) {
         List<DepartmentsDO> departmentDTOByClassesIdList = departmentsService.getDepartmentDTOByClassesIdList(ids);
        return CommonResult.success(DepartmentsConvert.INSTANCE.convertDepartmentDTOList(departmentDTOByClassesIdList));
    }

}
